App.module('dialogModule', function(dialogModule){
	var self = this;
	this.startWithParent = false;
	var _layout = null;
   var MainView = Marionette.ItemView.extend({
		tagName: 'div',
		events: {
			'click #form-submit': 'submit'
		},
		submit: function() {
			if (App.debug) console.log(self.moduleName + ' MainView::submit invoked');
		}
   });
	var Controller = Marionette.Controller.extend({
		initialize: function(options){
			if (App.debug) console.log(this.moduleName + ' Controller initialized');
			this.options = options;
		},
		show: function() {
			if (App.debug) console.log(this.moduleName + ' Controller show invoked');
         console.log(this.options);
			var main_view = new MainView({
				id: this.options.id,
				template: '#' + this.options.template
			});
			this.options.region.show(main_view);
		},
		render: function() {
			if (App.debug) console.log(this.moduleName + ' Controller render invoked');
			$('#main-dialog').wijdialog({});
			$(".form-input").wijtextbox();
			$(".form-submit").button();
		}
	});
	dialogModule.addInitializer(function (options) {
		var defaults = {
         id:                         'main-dialog',
         template:                   'main-dialog-template'
		};
      options = _.extend(defaults, options);
		if (App.debug) console.log('App.dialogModule addInitializer invoked');
		dialogModule.Controller = new Controller(options);
		dialogModule.Controller.show();
		dialogModule.Controller.render();
   });
});

App.dialogModule.on("before:start", function(){
	if (App.debug) console.log(this.moduleName + ' before:start');
});

App.dialogModule.on("start", function(){
	if (App.debug) console.log(this.moduleName + ' start');
});

